package co.edu.unal.geditor.view.tools;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;

import co.edu.unal.geditor.controller.App;
import co.edu.unal.geditor.controller.action.tool.LineToolAction;
import co.edu.unal.geditor.model.GraphElement;
import co.edu.unal.geditor.model.LineElement;

public class LineCreationTool extends CreationTool
{
	// v0.6 : LineCreationTool provides its own Factory class 
	private static class Factory extends ToolFactory
	{
		protected Tool create()
		{
			return new LineCreationTool();
		}
	}

	// this block executed when the class object is loaded in the VM
	// registers its Factory 
	static
	{
		ToolFactory.register( LineCreationTool.class.getName(), new Factory() );
	}

	@Override
	public GraphElement createObject( Point m_ptPressed, Point ptReleased )
	{
		return new LineElement( m_ptPressed, ptReleased );
	}

	@Override
	protected void initAction()
	{
		setAction( new LineToolAction() );
		if(feedbackGraphElemet==null)
		{
		feedbackGraphElemet = new LineElement(new Point(0,0), new Point(20,20));
		}
	}
	 @Override
     protected void drawFeedback( Graphics2D g )
     {
		    App.getInstance().getCanvas().getActiveFeedbackGraphElement().getBoundBox().setLeftUp(m_ptPressed);
			App.getInstance().getCanvas().getActiveFeedbackGraphElement().getBoundBox().setRightDown(m_ptCurrent);
			App.getInstance().getCanvas().getActiveFeedbackGraphElement().setLinesColor(Color.LIGHT_GRAY);
			App.getInstance().getCanvas().getActiveFeedbackGraphElement().paint(g);
             
			//g.drawLine( m_ptPressed.x, m_ptPressed.y, m_ptCurrent.x, m_ptCurrent.y );

     }
}
